import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver=webdriver.Chrome()
# driver=webdriver.Firefox()
driver.get('http://101.133.169.100/yuns/index.php')

#time.sleep(3)#强制等待3秒
#隐式等待
driver.implicitly_wait(10)#超时时间为10秒，超过10秒就会报错，如果在十秒以内加载完，就按最短时间算
driver.find_element_by_xpath('//*[@class="but1"]').send_keys('手机')
driver.find_element_by_xpath('//*[@class="but1"]').send_keys(Keys.ENTER)
driver.back()
time.sleep(2)#强制等待2秒，将会打破隐式等待
driver.find_element_by_xpath('//*[@class="but1"]').clear()
driver.find_element_by_xpath('//*[@class="but1"]').send_keys('电脑')
driver.find_element_by_xpath('//*[@class="but1"]').send_keys(Keys.ENTER)

#显式等待
locator = (By.XPATH,"//*[@class='but1']")
try:
    ele = WebDriverWait(driver, 10,1).until(EC.presence_of_element_located(locator))#最大等待时间为10秒，每隔1秒查看标签元素是否被加载
    driver.find_element_by_xpath("//*[@class='but1']").send_keys('手机')
    driver.find_element_by_xpath("//*[@class='but1']").send_keys(Keys.ENTER)
except:
    print("没有找到ele元素")
finally:
    driver.quit()